#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

#define MEM_SIZE		(1UL << 12)

static char *memk = NULL;
static char *memv = NULL;

static int __init mem_init(void) {
	printk(KERN_DEBUG "Mem test!\n");
	memk = (char *) kmalloc(MEM_SIZE, GFP_KERNEL);
	if (NULL == memk) {
		printk(KERN_ERR "kmalloc error!\n");
		return -1;
	}
	printk(KERN_DEBUG "kmalloc addr is 0x%lx\n", (unsigned long) memk);
	memv = (char *) vmalloc(MEM_SIZE);
	if (NULL == memv) {
		printk(KERN_ERR "vmalloc error!\n");
		return -1;
	}
	printk(KERN_DEBUG "vmalloc addr is 0x%lx\n", (unsigned long) memv);
	return 0;
}

static void __exit mem_exit(void) {
	printk(KERN_DEBUG "Mem test over\n");
	if (NULL != memk) {
		kfree(memk);
	}
	if (NULL != memv) {
		vfree(memv);
	}
	return ;
}

MODULE_LICENSE("GPL");
module_init(mem_init);
module_exit(mem_exit);
